ma = 8297
top = [5,10,20,30,40,50]
fpage = open("linkrate.txt")
page = []
for line in fpage:
    seq = [x for x in range(1, ma + 1)]
    link = dict.fromkeys(seq)
    date = line.split()
    for i in range(0,ma):
        link[i+1] = float(date[i])
    link = sorted(link.items(), key=lambda d:d[1], reverse = True)
    for i in range(0,50):
        page.append(link[i][0])
    # for k in link.items():
    #     print(k)
print(page)

hits = []
fhits = open("linka.txt")
for line in fhits:
    seq = [x for x in range(1, ma + 1)]
    link = dict.fromkeys(seq)
    date = line.split()
    for i in range(0,ma):
        link[i+1] = float(date[i])
    link = sorted(link.items(), key=lambda d:d[1], reverse = True)
    for i in range(0,50):
        hits.append(link[i][0])
    # for k in link.items():
    #     print(k)
print(hits)

for j in range(0,6):
    page1 = page[0:top[j]]
    hits1 = hits[0:top[j]]
    count = 0
    for i in range(0,top[j]):
        if page[i] in hits:
            count += 1
    print("top",top[j]," 的相似个数：",count," 相似率为：",count/top[j])
